package com.icbc.cc.security.app;

import java.util.Random;

public final class IdUtil {

	private static Random randGen = null;
	
	private static char[] numberAndLetters = null;
	
	private static Object initLock = new Object();
	
	/***
	 * 
	 * 生成49位的唯一随机码，由当前时间毫秒数加36个随机字符组成
	 * 
	 * ***/
	public static final String getRandomStr(){
		if(randGen==null){
			synchronized (initLock) {
				if(randGen==null){
					randGen = new Random();
					numberAndLetters = ("0123456789abcdefghijklmnopqrstuvwxyz").toCharArray();
				}
			}
		}
		char[] randBuffer = new char[7];
		for(int i=0;i<randBuffer.length;i++){
			randBuffer[i] = numberAndLetters[randGen.nextInt(36)];
		}
		return "" + new java.util.Date().getTime() + new String(randBuffer);
	}
	
	public static void main(String[] args){
		System.out.println(IdUtil.getRandomStr());
	}
	
	
}
